<template>
  <div>
    <el-form ref="form" :model="from"  label-width="80px">
      <el-form-item label="分类:">
        <el-select v-model="from.region" placeholder="请选择">
            <el-option label="请选择" value=""></el-option>
          <el-option label="分类1" value="1"></el-option>
          <el-option label="分类2" value="2"></el-option>
        </el-select>
        <el-select v-model="from.region1" placeholder="请选择" v-if="from.region!=''">
          <el-option label="分类1" value="1"></el-option>
          <el-option label="分类2" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="课程名称:" style="width: 300px;">
        <el-input v-model="from.name" placeholder="请输入课程名称"></el-input>
      </el-form-item>
      <el-form-item label="课程简介:" style="width: 450px">
        <el-input type="textarea" v-model="from.desc"></el-input>
      </el-form-item>
      <el-form-item label="关键字:" style="width: 400px">
        <el-input v-model="from.name" placeholder="请输入课程名称"></el-input>
        <span class="ss">*关键字与关键字之间用逗号隔开，长度3-30长度</span>
      </el-form-item>
      <el-form-item label="描述:" style="width: 400px;">
        <el-input v-model="from.name" placeholder="请输入描述"></el-input>
      </el-form-item>
      <el-form-item label="是否付费:" >
      <el-radio v-model="from.radio" label="1">付费</el-radio>
      <el-radio v-model="from.radio" label="2">免费</el-radio>
      </el-form-item>
      <el-form-item label="原价:" style="width: 300px;" v-if="this.from.radio==1 || this.from.radio==''">
        <el-input v-model="from.name" placeholder="请输入原价格"></el-input>
      </el-form-item>
      <el-form-item label="会员价:" style="width: 300px;"v-if="this.from.radio==1 || this.from.radio==''">
        <el-input v-model="from.name" placeholder="请输入会员价格"></el-input>
      </el-form-item>
      <el-form-item label="上传封面">
        <el-col :span="6" class="tt">
          <el-upload
            class="avatar-uploader"
            action
            :http-request="uploadImg"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>

        </el-col>
        <el-col :span="6">
          <div style="text-align: left; line-height:18px;font-size: 12px"class="s1">
            * 图片尺寸为800px*800px，仅支持jpg、jpeg、png 格式，图片大小不超过2MB。
          </div>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="onSubmit">下一步</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        from:{
          name:'',
          region:'',
          desc:'',
          radio:'',
          region1:''
        },
      }
    },
    created:{

    },
    methods:{
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      uploadImg(file) {//文件上传操作
        console.log("uploadFile", file.file);
        let formData = new FormData()
        formData.append('file',file.file)
        console.log("formData",formData);
        api.uploadImg(formData).then(res=>{
          if (res.code === 200) {
            console.log('图片上传成功')
          }
        })
      }
    }
  }
</script>

<style>
  .ss{
    font-size: 12px;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
  }
  .avatar {
    width: 100px;
    height: 100px;
    display: block;
  }
  .s1{
    width: 120px;
  }
  .tt{
    width:120px;
  }
</style>
